﻿using System;
using System.Collections;
using System.Collections.Specialized;
using System.Web;
using System.Web.SessionState;

namespace KWatkins.FluentMoqBuilder
{
	internal sealed class MockHttpSessionStateBase : HttpSessionStateBase
	{
		private readonly SessionStateItemCollection items = new SessionStateItemCollection();

		public override void Abandon()
		{
			items.Clear();
		}

		public override void Add(string name, object value)
		{
			items[name] = value;
		}

		public override void Clear()
		{
			items.Clear();
		}

		public override void Remove(string name)
		{
			items.Remove(name);
		}

		public override void RemoveAll()
		{
			items.Clear();
		}

		public override void RemoveAt(int index)
		{
			items.RemoveAt(index);
		}

		public override void CopyTo(Array array, int index)
		{
			Validate
				.Argument(array, "array")
				.IsNotNull();

			foreach(var item in this)
			{
				array.SetValue(item, index++);
			}
		}

		public override IEnumerator GetEnumerator()
		{
			return items.GetEnumerator();
		}

		public override int Count
		{
			get
			{
				return items.Count;
			}
		}

		public override bool IsSynchronized
		{
			get
			{
				return false;
			}
		}

		public override object SyncRoot
		{
			get
			{
				return this;
			}
		}

		public override object this[int index]
		{
			get
			{
				return items[index];
			}
			set
			{
				items[index] = value;
			}
		}

		public override object this[string name]
		{
			get
			{
				return items[name];
			}
			set
			{
				items[name] = value;
			}
		}

		public override SessionStateMode Mode
		{
			get
			{
				return SessionStateMode.Custom;
			}
		}

		public override NameObjectCollectionBase.KeysCollection Keys
		{
			get
			{
				return items.Keys;
			}
		}

		public override bool IsReadOnly
		{
			get
			{
				return false;
			}
		}

		public override HttpSessionStateBase Contents
		{
			get
			{
				return this;
			}
		}
	}
}